<?php

namespace app\models\search;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\CrmMallProduct;

/**
 * CrmMallProductSearch represents the model behind the search form of `app\models\CrmMallProduct`.
 */
class CrmMallProductSearch extends CrmMallProduct
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'specify_id'], 'integer'],
            [['spbm', 'spmc', 'spgg', 'sppp', 'spcd', 'gys', 'splx', 'spsx', 'dj', 'dlxl', 'sl', 'yhj', 'zje', 'bz'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = CrmMallProduct::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'specify_id' => $this->specify_id,
        ]);

        $query->andFilterWhere(['like', 'spbm', $this->spbm])
            ->andFilterWhere(['like', 'spmc', $this->spmc])
            ->andFilterWhere(['like', 'spgg', $this->spgg])
            ->andFilterWhere(['like', 'sppp', $this->sppp])
            ->andFilterWhere(['like', 'spcd', $this->spcd])
            ->andFilterWhere(['like', 'gys', $this->gys])
            ->andFilterWhere(['like', 'splx', $this->splx])
            ->andFilterWhere(['like', 'spsx', $this->spsx])
            ->andFilterWhere(['like', 'dj', $this->dj])
            ->andFilterWhere(['like', 'dlxl', $this->dlxl])
            ->andFilterWhere(['like', 'sl', $this->sl])
            ->andFilterWhere(['like', 'yhj', $this->yhj])
            ->andFilterWhere(['like', 'zje', $this->zje])
            ->andFilterWhere(['like', 'bz', $this->bz]);

        return $dataProvider;
    }
}
